#!/usr/bin/env node

console.log('hello world');

//./08-error.js
//echo $? 退出码为0


//抛出异常
//throw new Error('Something wrong');
//./08-error.js
//报错

//同步异常
//try{
  //throw new Error('something wrong');
//}catch(e){
  //console.log(e.message); 错误信息
  //process.exit(1); 退出码
//}

//./08-error.js
//程序没有崩溃 退出码是1



//异步异常
//try{
  //setImmediate(()=>{
     //process.exit();
     //throw new Error('something wrong');
  //});
//} catch(e){
  //console.log(e.message);
  //process.exit(1);
//}

//process.on('exit',()=>{
  //console.log('exit event emit');
  //process.exit();
//});
//./08-error.js



try{
  setImmediate(()=>{
     throw new Error('something wrong');
  });
} catch(e){
  console.log(e.message);
  process.exit(1);
}
//全局异常捕获，程序不会崩溃
process.on('uncaughtException',(err)=>{
  console.log(err.message);
  process.exit(1);
});

